var PATH_PREFIX5 ="";

function setPathPrefix5(path){
	PATH_PREFIX5 =  path;
}
$(function() {
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
    //初始化产品下拉框
    WASP_WIDGET.triggerPrdInfoSelect("prjCode");
});

var $orderManageList = $('#orderManageList');

$(function() {
	$orderManageList.jqGrid({   
		url:PATH_PREFIX5+'orderManageList.do',    
		//caption:'交易订单管理列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',  
		datatype: "json",
		postData:{
			'sp[prjCode]' : $("#orderMgr #prjCode").val(),
			'sp[directiveType]' : $("#directiveType").val()
		},  
		colNames:["主键","指令类型","产品ID","产品名称","证券代码","证券名称","委托方向","清算速度","交易对手","对方交易员号码","净价价格","全价价格","到期收益率","券面金额","指令数量","约定号","联系人","联系方式","备注","状态"/*,"操作"*/],        
		colModel:[  { name: 'orderId', index: 'orderId', hidden: true, key: true, resizable: true, sortable: false },       
		            { name: 'directiveType', index: 'directiveType', resizable: true,width:200, sortable: false ,
						formatter:function(cellvalue, options, rowObject){
			        		if(cellvalue =="largeAmountTransaction"){
			        			return "交易所大宗交易指令";
			        		}else if(cellvalue =="fixedIncomeTerrace"){
			        			return "上交所固定收益指令";
			        		}else if(cellvalue =="bankBondDeal"){
			        			return "银行间债券买卖指令";
			        		}else if(cellvalue =="banksBuyBack"){
			        			return "银行间质押式回购指令";
			        		}else if(cellvalue =="banksBuyBack2"){
			        			return "银行间买断式回购指令";
			        		}else if(cellvalue =="bondTransformTrusteeship"){
			        			return "银行间跨市场转托管指令";
			        		}else if(cellvalue =="openFundOpenAnAccount"){
			        			return "开放式基金开户指令";
			        		}else if(cellvalue =="openFundApplyAndAccount"){
			        			return "开放式基金申赎指令";
			        		}else if(cellvalue =="oneStairBondBid"){
			        			return "一级投标指令";
			        		}else if(cellvalue =="oneStairBondPayment"){
			        			return "一级缴款指令";
			        		}else if(cellvalue =="omnipotentOrder"){
			        			return "万能指令";
			        		}else if(cellvalue == null){
			        			return "";
			        		}else{
			        			return cellvalue;
			        		}
			        	}
			        },
		            { name: 'prjCode', index: 'prjCode', hidden: true,resizable: true, sortable: false },
		            { name: 'prjName', index: 'prjName', resizable: true, sortable: false },
		            { name: 'securitiesCode', index: 'securitiesCode', resizable: true, sortable: false },
		            { name: 'securitiesName', index: 'securitiesName', resizable: true, sortable: false },
		            { name: 'entrustAspect', index: 'entrustAspect', resizable: true, sortable: false },
		            { name: 'clearSpeed', index: 'clearSpeed', resizable: true, sortable: false },
		            { name: 'tradeOpponent', index: 'tradeOpponent', resizable: true, sortable: false },
		            { name: 'opponentTraderNum', index: 'opponentTraderNum', resizable: true, sortable: false },
		            { name: 'netprice', index: 'netprice', resizable: true, sortable: false },
		            { name: 'fullprice', index: 'fullprice', resizable: true, sortable: false },
		            { name: 'expireIncome', index: 'expireIncome', resizable: true, sortable: false },
		            { name: 'facevalueMoney', index: 'facevalueMoney', resizable: true, sortable: false },
		            { name: 'directiveAmount', index: 'directiveAmount', resizable: true, sortable: false },
		            { name: 'assumpsitNum', index: 'assumpsitNum', resizable: true, sortable: false },
		            { name: 'contacts', index: 'contacts', resizable: true, sortable: false },
		            { name: 'contactsWay', index: 'contactsWay', resizable: true, sortable: false },
		            { name: 'remark', index: 'remark', resizable: true, sortable: false },
		            { name: 'status', index: 'status', resizable: true, sortable: false ,
						formatter:function(cellvalue, options, rowObject){
			        		return "已复核";
			        	}
		            }/*,
		            { name: 'option', index: 'option', resizable: true, width:100, sortable: false }*/
				  ],
		rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: $(window).height()-220,
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: false,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		viewrecords: true,
		pager: "#orderManageListPage",						
		gridComplete: function(){
			var ids = $orderManageList.jqGrid('getDataIDs');
			for (var i = 0; i < ids.length; i++) {
				var rowId = ids[i];
				deleteBtn = '<a class="btn btn-link btn-jqgrid" title="删除" onclick="deleteView(\'' + rowId + '\');" >删除</a>';
				$orderManageList.jqGrid('setRowData', ids[i], {
					option : deleteBtn
				});
			}
		}
	});
	$orderManageList.navGrid('#orderManageListage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$orderManageList.jqGrid('setFrozenColumns');
	jqGridResize($orderManageList);
	$(".ui-jqgrid .ui-jqgrid-htable").css("width",$(".ui-jqgrid .ui-jqgrid-htable").width()+18);
	$(".ui-jqgrid .ui-jqgrid-btable").css("width",$(".ui-jqgrid .ui-jqgrid-htable").width()+18);
});

/**
 * 查询按钮
 * 根据条件查询数据
 * @param flag
 */
function queryByCondtion4(flag){
    var postData = $orderManageList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
    	'sp[prjCode]' : $("#orderMgr #prjCode").val(),
		'sp[directiveType]' : $("#directiveType").val()
	});
    if (flag) {
    	$orderManageList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid",[{page:1}]);//重新载入Grid表格
    } else {
    	$orderManageList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid");//重新载入Grid表格
    }
}